@extends('admin.layouts.default')
@section('content')

    <div class="card">
        <div class="card-body">
            <ul class="nav nav-tabs nav-overflow header-tabs">
                <li class="nav-item">
                    <a href="{{route('admin.role.index')}}" class="nav-link  pb-3 active">
                        角色列表
                    </a>
                </li>
                <li class="nav-item">
                    <a href="{{route('admin.role.create')}}" class="nav-link pb--3 ">
                        添加角色
                    </a>
                </li>
            </ul>
        </div>

        <div class="card-body small">
            <table class="table">
                <thead>
                <tr>
                    <th>编号</th>
                    <th>角色</th>
                    <th>角色描述</th>
                    <th>创建时间</th>
                </tr>
                </thead>
                <tbody>
                @foreach($roles as $role)
                    <tr>
                        <td scope="row">{{$role['id']}}</td>
                        <td>{{$role['name']}}</td>
                        <td>{{$role['title']}}</td>
                        <td>{{$role['created_at']->format('Y/m/d')}}</td>
                        <td class="text-right">
                            <div class="btn btn-group-sm" role="group" aria-label="First group">
                                <a href="{{route('admin.role.edit',$role)}}" class="btn btn-secondary btn-sm">编辑角色</a>
                                {{--系统超级管理员拥有所有权限不需要再编辑权限--}}
                                @if($role['id'] != 1)
                                    <a href="{{route('admin.role.permission',$role)}}" class="btn  btn-secondary">分配权限</a>
                                @endif
                                @if(!$role['system'])
                                    <button type="button" class="btn btn-sm btn-danger" onclick="del(this)">删除角色
                                    </button>
                                    <form action="{{route('admin.role.destroy',$role)}}" method="post">
                                        @csrf @method('DELETE')
                                    </form>
                                @endif
                            </div>
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>
    {{$roles->links()}}
@endsection
@push('js')
    <script>
        function del(obj) {
            require(['hdjs'],function (hdjs) {
                hdjs.confirm('确定要删除吗?',function () {
                    $(obj).next().submit();
                })
            })
        }
    </script>
@endpush